package org.akomantoso.core.data;

import java.io.IOException;

import org.akomantoso.core.data.attribute.Link;
import org.akomantoso.core.data.attribute.Notes;
import org.akomantoso.core.data.group.ANmarker;
import org.akomantoso.core.data.type.PlacementType;
import org.akomantoso.core.io.Input;
import org.akomantoso.core.io.Output;
import org.akomantoso.core.io.OutputUtil;
import org.akomantoso.core.visitor.AKVisitor;

/**
 * The element noteRef is a reference to a editorial note placed in the notes metadata section.
 * 
 * <pre>
 * 	<xsd:element name="noteRef">
 * 		<xsd:complexType>
 * 			<xsd:complexContent>
 * 				<xsd:extension base="markeropt">
 * 					<xsd:attributeGroup ref="notes"/>
 * 					<xsd:attributeGroup ref="link"/>
 * 				</xsd:extension>
 * 			</xsd:complexContent>
 * 		</xsd:complexType>
 * 	</xsd:element>
 * </pre>
 * 
 * @author <a href="mailto:jacques.militello@gmail.com">Jacques Militello</a>
 * 
 * @since http://www.akomantoso.org/1.0
 * 
 */
public final class NoteRef extends MarkerOpt implements Link, Notes, ANmarker{

	public static final String ELEMENT = "noteRef";

	private String _href;
	private String _marker;
	private PlacementType _placementType; 
	private String _placementBase;

	/**
	 * @see org.akomantoso.core.data.attribute.Notes#getMarker()
	 */
	@Override
	public String getMarker() {
		return _marker;
	}

	/**
	 * @see org.akomantoso.core.data.attribute.Notes#setMarker(java.lang.String)
	 */
	@Override
	public void setMarker(String marker) {
		_marker = marker;
	}

	/**
	 * @see org.akomantoso.core.data.attribute.Notes#getPlacement()
	 */
	@Override
	public PlacementType getPlacement() {
		return _placementType;
	}

	/**
	 * @see org.akomantoso.core.data.attribute.Notes#setPlacement(org.akomantoso.core.data.type.PlacementType)
	 */
	@Override
	public void setPlacement(PlacementType placement) {
		_placementType = placement;
	}

	/**
	 * @see org.akomantoso.core.data.attribute.Notes#getPlacementBase()
	 */
	@Override
	public String getPlacementBase() {
		return _placementBase;
	}

	/**
	 * @see org.akomantoso.core.data.attribute.Notes#setPlacementBase(java.lang.String)
	 */
	@Override
	public void setPlacementBase(String placementBase) {
		_placementBase = placementBase;
	}

	/**
	 * @see org.akomantoso.core.data.attribute.Link#getHref()
	 */
	@Override
	public String getHref() {
		return _href;
	}

	/**
	 * @see org.akomantoso.core.data.attribute.Link#setHref(java.lang.String)
	 */
	@Override
	public void setHref(String href) {
		_href = href;
	}

	/**
	 * @see org.akomantoso.core.data.MarkerOpt#writeExternal(org.akomantoso.core.io.Output)
	 */
	@Override
	public <T extends Output> void writeExternal(T out) throws IOException {
		out.writeStart(ELEMENT);
		OutputUtil.writeLink(out, this);
		OutputUtil.writeNotes(out, this);
		super.writeExternal(out);
		out.writeEnd();
	}

	
	
	/**
	 * @see org.akomantoso.core.data.CoreOptImpl#readExternal(org.akomantoso.core.io.Input)
	 */
	@Override
	public <T extends Input> void readExternal(T in) throws IOException {
		_href = in.readAttribute(Link.ATTRIBUTE);
		_marker = in.readAttribute(Notes.ATTRIBUTE_MARKER);
		_placementBase = in.readAttribute(Notes.ATTRIBUTE_PLACEMENT_BASE);
		_placementType = PlacementType.checkValueOf(in.readAttribute(Notes.ATTRIBUTE_PLACEMENT));
		super.readExternal(in);
	}

	/**
	 * @see org.akomantoso.core.visitor.AKVisitable#accept(org.akomantoso.core.visitor.AKVisitor)
	 */
	@Override
	public void accept(AKVisitor visitor) {
	}
	
	
}
